'use strict';

import React, {Component, PropTypes} from 'react';
import {Grid, Col, Divider} from 'amazeui-react';
import {
  STRING,
  API
} from '../res';
import {DateTime} from '../lib';

export default class SinglePlanDetail extends Component {
	/*
	 * 构造函数。
	 * @param props 属性
	 */
	constructor(props) {
		super(props);
		this.state = {};
	}

  /*
	 * 获取附件列表。
	 * @param value 附件
	 */
	getAttachList(value) {
		value = value !== undefined ? value.split(',') : [];
		value = value.map((x, i) => {
			return (
				<li key={i}>
					<a
						href={API.uploads + x}
						className="am-block"
					>{x}</a>
				</li>
			);
		});

		return <ul>{value}</ul>;
	}

	/*
	 * 渲染。
	 */
	render() {
		const data = this.props.data;
		const attachs = this.getAttachList(data.attach);

		const divStyle = {
			overflowY: 'auto',
			maxHeight: '100%'
		};

		return (
			<div style={divStyle}>
				<Grid>
					<Col sm={6}>
						<p>{STRING.relevanceSchool + '：' + (data.relationSchoolName || '')}</p>
						<p>{STRING.writer + '：' + (data.actionPersonName || '')}</p>
					</Col>
					<Col sm={6}>
						<p>{STRING.writeDate + '：' + DateTime.format(data.updateTime)}</p>
					</Col>
				</Grid>
				<Grid>
					<Col sm={12}>
						<p>{STRING.predictDate + '：' + DateTime.format(data.expectActionTime)}</p>
						<p>{STRING.DDTheme + '：' + (data.themeName || '')}</p>
						<Divider />
						<h2>{STRING.comprehensivePlan}</h2>
						<p>{data.content}</p>
						<h2>{STRING.liaisonAdvice}</h2>
						<pre>{data.liaisonAdvice}</pre>
						<h2>{STRING.leaderAdvice}</h2>
						<pre>{data.leaderAdvice}</pre>
						<h2>{STRING.assistantInspector}</h2>
						<pre>{data.cooperationPersonName}</pre>
            <h2>{STRING.attach}</h2>
            {attachs}
					</Col>
				</Grid>
			</div>
		);
	}
}

SinglePlanDetail.propTypes = {
	data: PropTypes.object
};
SinglePlanDetail.defaultProps = {};
